<?php
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace frontend\v1;

use Yii;

/**
 * v1接口
 * @author cleverstone
 * @since ym2.0
 */
class Module extends \yii\base\Module
{
    /**
     * @var string  The version of this module. Note that the type of this property differs in getter
     */
    public $version = '1.0.0';

    /**
     * @var string
     */
    public $controllerNamespace = 'frontend\v1\controllers';

    /**
     * @var string the default route of this module. Defaults to `default`.
     * The route may consist of child module ID, controller ID, and/or action ID.
     * For example, `help`, `post/create`, `admin/post/create`.
     * If action ID is not given, it will take the default value as specified in
     * [[Controller::defaultAction]].
     */
    public $defaultRoute = 'index';

    /**
     * @var string|bool the layout that should be applied for views within this module. This refers to a view name
     * relative to [[layoutPath]]. If this is not set, it means the layout value of the [[module|parent module]]
     * will be taken. If this is `false`, layout will be disabled within this module.
     */
    public $layout = 'main';

    /**
     * {@inheritdoc}
     */
    public function init()
    {
        // Set error page route.
        $this->setErrorPageRoute();
        // Set [yii\web\User::enableSession] equal `false`
        $this->disableWebUserSession();
        // Set [yii\web\Request::enableCsrfCookie] and [yii\web\Request::enableCookieValidation] equal `false`
        $this->disableRequestCookie();

        parent::init();
    }

    protected function setErrorPageRoute()
    {
        Yii::$app->errorHandler->errorAction = 'v1/error/index';
    }

    protected function disableWebUserSession()
    {
        Yii::$app->user->enableSession = false;
    }

    protected function disableRequestCookie()
    {
        $request = Yii::$app->request;
        $request->enableCsrfCookie = false;
        $request->enableCookieValidation = false;
    }
}